package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.log.enums.BusinessType;
import com.spzx.product.bitmap.BitmapSyncService;
import com.spzx.product.domain.Product;
import com.spzx.product.service.ProductService;
import com.spzx.product.vo.ProductVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author lynn
 * @since 2025-03-12
 */
@RestController
@RequestMapping("/product")
@Tag(name = "商品")
public class ProductController extends BaseController {
    @Autowired
    private ProductService productService;

    @Operation(summary = "查询商品列表")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<ProductVo> list = productService.selectProductList();
        return getDataTable(list);
    }

    @Operation(summary = "删除商品",description = "根据商品id删除商品")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @Parameter(name = "ids", description = "商品id数组")
            @PathVariable Long[] ids)
    {
        return toAjax(productService.removeBatchIds(List.of(ids)));
    }

    @PostMapping
    @Operation(summary = "新增商品")
    public AjaxResult add(
            @Parameter(description = "商品")
            @RequestBody Product product) {
        return toAjax(productService.insertProduct(product));
    }


    @Operation(summary = "更新上下架状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public AjaxResult updateStatus(
            @Parameter(description = "商品id") @PathVariable Long id,
            @Parameter(description = "状态") @PathVariable Integer status) {
        if(status != 1 && status != -1){
            return AjaxResult.error("status值非法");
        }
        return toAjax(productService.updateStatus(id, status));
    }
}
